package com.michale.common.exception;

import io.swagger.annotations.ApiModelProperty;

/**
 * @author Michale
 * @apiNote 自定义业务异常
 */
public final class ServiceException extends RuntimeException {

    private static final long serialVersionUID = 1L;

    @ApiModelProperty("业务名称")
    private String name;

    @ApiModelProperty("错误码")
    private Integer code;

    @ApiModelProperty("错误提示")
    private String msg;

    @ApiModelProperty("错误明细，内部调试错误")
    private String detailMessage;

    public ServiceException() {
    }

    public ServiceException(String name, Throwable e) {
        super(e.getMessage(), e);
        this.name = name;
    }

    public ServiceException(String msg) {
        this.msg = msg;
    }

    public ServiceException(String msg, Integer code) {
        this.msg = msg;
        this.code = code;
    }

    public ServiceException(String name, String msg, Integer code) {
        this.name = name;
        this.msg = msg;
        this.code = code;
    }

    public ServiceException(String name, String msg) {
        this.name = name;
        this.msg = msg;
    }

    public String getDetailMessage() {
        return detailMessage;
    }

    public String getName() {
        return name;
    }

    @Override
    public String getMessage() {
        return msg;
    }

    public Integer getCode() {
        return code;
    }

    public ServiceException setMessage(String msg) {
        this.msg = msg;
        return this;
    }

    public ServiceException setDetailMessage(String detailMessage) {
        this.detailMessage = detailMessage;
        return this;
    }
}